from flask import Flask,jsonify,json,request
from dao import BaseDao
import json
import test
import logging
import jsonResult

app = Flask(__name__)

# 日志配置
logger = logging.getLogger()
logger.setLevel(logging.INFO)
res = jsonResult.R()

@app.route('/')
def hello_world():
    case = test.TestCase()
    case.methodA()
    return 'Hello World!'

@app.route("/testQuery")
def  testQuery():
    sql = "select * from student"
    result = BaseDao.query(sql)
    return json.dumps(result, ensure_ascii=False)

'''
登录
'''
@app.route("/login",methods={"GET","POST"})
def login():
    username = request.args.get("username")
    print(request.args)
    password = request.args.get("password")
    sql = "select * from student where stu_no='%s'" % username
    result = BaseDao.query(sql)
    # logging.info("日志信息输出.......%s",username)
    if len(result)>0:
        if result[0][6] == password:
            return res.ok("登录成功")
        else:
            return res.error()
    else:
        return res.error()




if __name__ == '__main__':
    app.run(host="127.0.0.1",port=8888,debug=True)
